package com.itheima.advantagesup.controller;


import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.dto.UserInfoDTO;
import com.itheima.advantagesup.vo.UsersPageBeanVO;
import com.itheima.advantagesup.service.SysUserService;
import com.itheima.advantagesup.vo.UserInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/sys_user")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/list")
    public R page(String login_name, Integer status, String phone, Integer page, Integer limit) {
        UsersPageBeanVO usersPageBeanVO = sysUserService.page(login_name, status, phone, page, limit);
        return R.success(usersPageBeanVO);
    }

    @PostMapping("/add")
    public R add(@RequestBody UserInfoDTO userInfoDTO){
        log.info("添加管理员:{}",userInfoDTO);
        sysUserService.add(userInfoDTO);
        return R.success();
    }

    @GetMapping("del")
    public R delete(String id){
        log.info("删除用户根据id:{}",id);
        sysUserService.delete(id);
        return R.success();
    }

    @GetMapping("/rowInfo")
    public R getUserById(String id){
        log.info("找到用户根据id:{}",id);
        UserInfoVO userInfoVO = sysUserService.getUserById(id);
        return R.success(userInfoVO);
    }

    @PostMapping("/update")
    public R update(@RequestBody UserInfoDTO userInfoDTO){
        log.info("修改员工:{}",userInfoDTO);
        sysUserService.update(userInfoDTO);
        return R.success();
    }
}
